package org.ourgrid.worker.business.requester;

import java.util.ArrayList;
import java.util.List;

import org.ourgrid.common.interfaces.to.GridProcessErrorTypes;
import org.ourgrid.common.internal.IResponseTO;
import org.ourgrid.worker.business.controller.GridProcessError;
import org.ourgrid.worker.request.ExecutionErrorRequestTO;
import org.ourgrid.worker.response.ErrorOcurredMessageHandleResponseTO;

public class ExecutionErrorRequester extends AbstractWorkerExecutionClientRequester<ExecutionErrorRequestTO> {

	public List<IResponseTO> execute(ExecutionErrorRequestTO request) {
		List<IResponseTO> responses = new ArrayList<IResponseTO>();
		
		if (getWorkerClientAddress() != null) {
			
			ErrorOcurredMessageHandleResponseTO to = new ErrorOcurredMessageHandleResponseTO(new GridProcessError(request.getError(), GridProcessErrorTypes.EXECUTION_ERROR),
					getWorkerStatusDAO().getConsumerAddress());
			to.setClientAddress(getWorkerClientAddress());
			
			responses.add(to);
			
			setExecutionAsFinished(false);
		}
		
		return responses;
	}

}
